package com.coreservlets.jsf.ss12;

import java.io.Serializable;

public class ABCGame implements Serializable
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String actualState = "A";
	private String message = "50/50 chance of \"B\" or \"Defeat\"";

	public String getActualState() 
	{
		return actualState;
	}

	public void setActualState(String actualState) 
	{
		this.actualState = actualState;
	}
	
	public String play()
	{
		if( actualState.equals( "A") )
		{
			if( Math.random() < 0.5 )
			{
				actualState = "B";
				message = "50/50 chance of \"C\" or \"Defeat\"";
			}
			else
			{
				actualState = "LOST";
				message = "You have LOST";
			}
		}
		else if( actualState.equals( "B" ) )
		{
			if( Math.random() < 0.5 )
			{
				actualState = "C";
				message = "50/50 chance of \"Victory\" or \"Defeat\"";
			}
			else
			{
				actualState = "LOST";
				message = "You have LOST";
			}
		}
		else if( actualState.equals( "C" ) )
		{
			if( Math.random() < 0.5 )
			{
				actualState = "WON";
				message = "You have WON";
			}
			else
			{
				actualState = "LOST";
				message = "You have LOST";
			}
		}
		
		return( null );
	}

	public String getMessage() 
	{
		return message;
	}

	public void setMessage(String message) 
	{
		this.message = message;
	}
	
	public String restartGame()
	{
		actualState = "A";
		message = "50/50 chance of \"B\" or \"Defeat\"";
		
		return( null );
	}
}
